package com.powernode.spring6.annotation;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

// 切面类 通知
@Aspect
@Component
public class MyAspect {

    // 前置通知
    @Before("execution(* com.powernode.spring6.service..*(..))")
    // 这就是需要增强的代码（通知）
    public void BeforeAdvice(){
        System.out.println("我是一个前置通知Before");
    }

    // 后置通知
    @AfterReturning("execution(* com.powernode.spring6.service..*(..))")
    public void AfterReturningAdvice() {
        System.out.println("我是一个后置通知绕AfterReturning");
    }

    // 环绕通知
    @Around(value = "execution(* com.powernode.spring6.service..*(..))")
    public void AroundAdvice(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("我是一个环绕通知开始Around");
        joinPoint.proceed();
        System.out.println("我是一个环绕通知结束Around");
    }

    // 异常通知
    @AfterThrowing(value = "execution(* com.powernode.spring6.service..*(..))")
    public void AfterThrowingAdvice() {
        System.out.println("我是一个异常通知AfterThrowing");
    }

    // 最终通知
    @After(value = "execution(* com.powernode.spring6.service..*(..))")
    public void afterAdvice(){
        System.out.println("最终通知");
    }
}
